/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//var ajaxUrl = ( "http://" + window.location.host + "/ajax" );
var ajaxUrl = 'ajax';
function showGames(IDLeague){
    $.ajax({
            url: ajaxUrl,
            type: 'post',
            data: {
                action: '1',
                IDLeague: IDLeague
            },
            dataType: 'text', 
            success: showGamesCallback
        })
}
function showGamesCallback(data){
    var html = "";
    var json = eval("(" + data + ")");
    var games = json.games;
    if(games.length == 0){
        html += "<div class='prediction-list'>";
        html += "<h2><label>No predictions for this league</label></h2>";
        html += "</div>"
    }else{
        html += "<div class='prediction-list'>";
        html += "<h2><label>"+json.league+"</label></h2>";
        html += "<div class='block dark'>";
        html += "<div class='table-text' style='width: 20%'></div>";
        html += "<div class='table-text' style='width: 28%; text-align: right;'>HOME</div>";
        html += "<div class='table-text' style='width: 4%'>-</div>";
        html += "<div class='table-text' style='width: 28%; text-align: left;'>AWAY</div>";
        html += "<div class='table-text' style='width: 20%'>Prediction</div>";
        html += "</div>"
        for(var i=0; i<games.length; i++){
            var a = i + 1;
            html += "<div class='block light'>";
            html += "<div class='table-text' style='width: 20%'>"+a+"</div>";
            html += "<div class='table-text' style='width: 28%; text-align: right;'>"+games[i].homeTeam+"</div>";
            html += "<div class='table-text' style='width: 4%'>-</div>";
            html += "<div class='table-text' style='width: 28%; text-align: left;'>"+games[i].awayTeam+"</div>";
            html += "<div class='table-text' style='width: 20%'>"+games[i].tip+"</div>";
            html += "</div>"
        }
        html += "</div>"
    }
    
    $('#games').html(html);
    $('.back-to-top-predictions').css('display', 'block');
}
function showLeagues(IDCountry){
    $.ajax({
            url: ajaxUrl,
            type: 'post',
            data: {
                action: '2',
                IDCountry: IDCountry
            },
            dataType: 'text', 
            success: showLeaguesCallback
        })
}
function showLeaguesCallback(data){
    var html = "";
    var json = eval("(" + data + ")");
    var leagues = json.leagues;
    if(leagues.length == 0){
        html += "<div class='prediction-list'>";
        html += "<h2><label>No predictions</label></h2>";
        html += "</div>"
    }else{
        for(var j=0; j<leagues.length; j++){
            html += "<div class='prediction-list'>";
            html += "<h2><label>"+leagues[j].fullName+"</label></h2>";
            html += "<div class='block dark'>";
            html += "<div class='table-text' style='width: 20%'></div>";
            html += "<div class='table-text' style='width: 28%; text-align: right;'>HOME</div>";
            html += "<div class='table-text' style='width: 4%'>-</div>";
            html += "<div class='table-text' style='width: 28%; text-align: left;'>AWAY</div>";
            html += "<div class='table-text' style='width: 20%'>Prediction</div>";
            html += "</div>"
            var games = leagues[j].games;
            for(var i=0; i<games.length; i++){
                var a = i + 1;
                html += "<div class='block light'>";
                html += "<div class='table-text' style='width: 20%'>"+a+"</div>";
                html += "<div class='table-text' style='width: 28%; text-align: right;'>"+games[i].homeTeam+"</div>";
                html += "<div class='table-text' style='width: 4%'>-</div>";
                html += "<div class='table-text' style='width: 28%; text-align: left;'>"+games[i].awayTeam+"</div>";
                html += "<div class='table-text' style='width: 20%'>"+games[i].tip+"</div>";
                html += "</div>"
            }
        }
        html += "</div>";
    }
    $('#games').html(html);
    $('.back-to-top-predictions').css('display', 'block');
}
function collapseList(id){
    $('.side-menu li.' + id).toggle();
}
$(document).ready(function(){
    $('.banner iframe').css('position','relative');
});
